﻿
@{
    ViewBag.Title = "Edit";
    Layout = "~/Views/Shared/MainLayout.cshtml";
}

<script type="text/javascript">
    $(function () {
        //导航切换
        $(".menuson li.active").removeClass("active");
        $("#teacherItem").addClass("active");

        $("#btnBack").click(function () {
            window.location = "/Teacher/Index";
        });
        CheckForm(); //规则验证
    });
    function CheckForm() {
        //密码验证
        jQuery.validator.addMethod("pwdReg", function (value, element) {
            var nameReg = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,12}$/;
            return this.optional(element) || nameReg.test(value);
        }, "错误：英文字母和数字组成的6~20位字符构成！");

        $("#editFrm").validate({
            rules: {
                Name: { required: true, maxlength: 20 },//用户名非空,长度不能超过20
                LoginName: {
                    required: true,
                    remote: {
                        url: '/Teacher/UserHasedForEdit',
                        type: 'post',
                        data: {
                            LoginName: function () {
                                return $("#LoginName").val();
                            },
                            OldLoginName: function () {
                                return $("#OldLoginName").val();
                            }
                        }
                    }
                },//登录名非空
                LoginPwd: { required: true, pwdReg: true },//密码非空,自定义正则规则
                Roles: { required: true }
            },
            messages: {
                Name: { required: "请输入用户名！", maxlength: "错误：不能超过20个字符" },
                LoginName: { required: "请输入登录名！", remote: "登录名已存在！" },
                LoginPwd: { required: "请输入密码！" },
                Roles: { required: "请输入角色！" },
            },
            errorElement: "i",//错误信息显示标签名
            errorClass: "invalid"//错误信息及标签样式

        });
    }
</script>
<style type="text/css">
    .invalid {
        color: red; /*红色显示*/
    }
</style>
<div class="place">
    <span>位置：</span>
    <ul class="placeul">
        <li><a href="#">首页</a></li>
        <li><a href="#">顾问信息</a></li>
        <li><a href="#">编辑顾问</a></li>
    </ul>
</div>
@using (Html.BeginForm("Edit", "Teacher", FormMethod.Post, new { id = "editFrm", name = "editFrm" }))
{
    <div class="formbody">
        <div class="formtitle"><span>基本信息</span></div>
        @Html.Hidden("ID", ViewBag.Teacher.ID as string)
        <ul class="forminfo">
            <li><label>顾问名称</label>@Html.TextBox("Name", ViewBag.Teacher.Name as string, new { @class = "dfinput" })<i> </i></li>
            <li><label>登录名</label>
            @Html.Hidden("OldLoginName",ViewBag.Teacher.LoginName as string) <!--隐藏修改前的登录名-->
            @Html.TextBox("LoginName", ViewBag.Teacher.LoginName as string, new { @class = "dfinput" })<i> </i></li>
            <li><label>登录密码</label>@Html.TextBox("LoginPwd", ViewBag.Teacher.LoginPwd as string, new { @class = "dfinput" })<i></i></li>
            <li>
                <label>性别</label>
                @if (ViewBag.Teacher.Sex)
                {
                    <label>@Html.RadioButton("Sex", "true", new { @checked = "Checked" }) 男 @Html.RadioButton("Sex", "false") 女</label>
                }
                else
                {
                    <label>@Html.RadioButton("Sex", "true") 男 @Html.RadioButton("Sex", "false", new { @checked = "Checked" })女</label>
                }
                <i><cite>&nbsp;</cite></i>
            </li>
            <li><label>电话</label>@Html.TextBox("Phone", ViewBag.Teacher.Phone as string, new { @class = "dfinput" })<i></i></li>
            <li><label>邮箱</label>@Html.TextBox("Email", ViewBag.Teacher.Email as string, new { @class = "dfinput" })<i></i></li>
            <li><label>角色</label>@Html.TextBox("Roles", ViewBag.Teacher.Roles as string, new { @class = "dfinput" })<i>例如：管理员，就业顾问，技术顾问，辅导员 </i></li>
            <li>
                <label>&nbsp;</label><input name="btnSave" type="submit" class="btn" value="确认保存" />
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input id="btnBack" name="btnBack" type="button" class="btn" value="取消并返回" />
            </li>
        </ul>
    </div>
}



